﻿// ParseLib - An open source library for natural language processing.
// Copyright (C) Kais Dukes, 2012. E-mail: kais@kaisdukes.com
// http://parselib.org

using System.Collections.Generic;
using ParseLib.Corpora;
using ParseLib.Tagging.Brill.Rules;

namespace ParseLib.Tagging.Brill
{
    public class BrillTagger : IPartOfSpeechTagger
    {
        public int Threshold { get; set; }
        public Lexicon Lexicon { get; set; }
        public List<Rule> Rules { get; private set; }

        public BrillTagger()
        {
            Rules = new List<Rule>();
            Threshold = 1;
        }

        public void Train(IEnumerable<TextualUnit> trainingData)
        {
            new BrillTrainer().Train(this, trainingData);
        }

        public void Tag(TextualUnit textualUnit)
        {
            // Initial tagging.
            var sentence = new Sentence(textualUnit, Lexicon);

            // Apply rules.
            foreach (var rule in Rules)
            {
                rule.Apply(sentence);
            }

            // Final tags.
            var size = sentence.TokenCount;
            for (var i = 0; i < size; i++)
            {
                var token = sentence[i];
                token.CorrectTag = token.CurrentTag;
            }
        }
    }
}